<template>
    <div class="edu-page-warp">
      <inner-breadcrumb v-model="pathKey" :path="path"></inner-breadcrumb>
      <template v-if="pathKey=='main'">
        <condition-card @reset="reset" @search="handleFilterSubmit">
            <el-row :gutter="24">
                <el-col :span="8">
                    <el-form-item :label="$t('teachers.nationalityLabel')" prop="country">
                        <el-select v-model="queryForm.country" filterable style="width: 100%">
                            <el-option
                                v-for="item in options.country"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item :label="$t('teachers.facultyLabel')" prop="faculty">
                        <el-select v-model="queryForm.faculty" filterable style="width: 100%">
                            <el-option
                                v-for="item in options.faculty"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item :label="$t('teachers.genderLabel')" prop="sex">
                        <el-select v-model="queryForm.sex" filterable style="width: 100%">
                            <el-option
                                v-for="item in options.sex"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="8">
                    <el-form-item :label="$t('teachers.titleLabel')" prop="title">
                        <el-select v-model="queryForm.title" filterable style="width: 100%">
                            <el-option
                                v-for="item in options.title"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item :label="$t('teachers.isTeachQual')" prop="teachQual">
                        <el-select v-model="queryForm.teachQual" style="width: 100%">
                            <el-option
                                v-for="item in options.teachQual"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8" v-if="global.isUndergraduate">
                    <el-form-item :label="$t('teachers.age')">
                        <el-row>
                            <el-col :span="11">
                                <el-input
                                    v-model="queryForm.minAge"
                                    oninput="value=value.replace(/[^\d]/g,'')"
                                    :placeholder="$t('inputPlaceholder')"
                                    maxlength="2"
                                />
                            </el-col>
                            <el-col :span="2" style="text-align:center">-</el-col>
                            <el-col :span="11">
                                <el-input
                                    v-model="queryForm.maxAge"
                                    oninput="value=value.replace(/[^\d]/g,'')"
                                    :placeholder="$t('inputPlaceholder')"
                                    maxlength="2"
                                />
                            </el-col>
                        </el-row>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item :label="$t('teachers.state')" prop="stateId">
                        <el-select v-model="queryForm.stateId" filterable style="width: 100%">
                            <el-option
                                v-for="item in options.state"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
        </condition-card>
        <el-card v-loading="loading" shadow="never">
            <div class="edu-page-title" style="margin-bottom:16px;">{{$t('teachers.teachersMgt')}}</div>
            <div class="edu-opertion-bar" style="margin-bottom:16px">
                <div class="float-left">
                    <el-input
                        style="width: 220px"
                        v-model="queryForm.condition"
                        :placeholder="$t('common.pla.teacherNameCode')"
                        @keyup.enter.native="handleCondition"
                    >
                        <i
                            slot="suffix"
                            class="el-input__icon el-icon-search"
                            @click="handleCondition"
                        ></i>
                    </el-input>
                </div>
                <div class="float-right">
                    <el-button type="primary" @click="batchEditTeachers">{{$t("teachers.batchEditTeachers")}}</el-button>
                    <el-button
                        type="primary"
                        @click="handleExportSchemes"
                    >{{$t('common.btn.export')}}</el-button>
                    <el-button v-if="!(global.isUndergraduate && global.isAcdemicDean)" type="primary" @click="handleSubmit()">{{$t('teachers.setQual')}}</el-button>
                </div>
            </div>
            <el-table
                :data="teacherList"
                stripe
                style="width: 100%"
                @select="selectRow"
                @selection-change="selectionChange"
                tooltip-effect="light"
            >
                <edu-table-column type="selection" width="30" />
                <edu-table-column
                    :label="$t('message.order')"
                    type="index"
                    align="center"
                    width="60"
                />
                <edu-table-column
                    :label="$t('teachers.code')"
                    prop="code"
                    :render-header="labelHead"
                />
                <edu-table-column :label="$t('teachers.teacherName')" :render-header="labelHead">
                    <template slot-scope="scope">
                        <el-button
                            @click="handleNameClick(scope.row)"
                            type="text"
                        >{{scope.row.name}}</el-button>
                    </template>
                </edu-table-column>
                <edu-table-column
                    :label="$t('teachers.gender')"
                    prop="sexI18n"
                    :render-header="labelHead"
                />
                <edu-table-column
                    :label="$t('teachers.faculty')"
                    prop="facultyI18n"
                    :render-header="labelHead"
                />
                <edu-table-column
                    :label="$t('teachers.nationality')"
                    prop="countryI18n"
                    :render-header="labelHead"
                />
                <edu-table-column
                    :label="$t('teachers.age')"
                    prop="age"
                    :render-header="labelHead"
                />
                <edu-table-column
                    :label="$t('teachers.title')"
                    prop="title"
                    :render-header="labelHead"
                />
                <edu-table-column
                    :label="$t('teachers.phone')"
                    prop="phone"
                    :render-header="labelHead"
                />
                <edu-table-column
                    :label="$t('teachers.email')"
                    prop="email"
                    :render-header="labelHead"
                />
                <!--身份证标识-->
                <edu-table-column :label="$t('teachers.card')" :render-header="labelHead">
                    <template slot-scope="scope">{{getCard(scope.row)}}</template>
                </edu-table-column>
                <edu-table-column
                    :label="$t('teachers.postTeachQualOnjob')"
                    :render-header="labelHead"
                    v-if="this.global.projectId === '4'"
                >
                    <template slot-scope="scope">
                        <el-tag
                            v-if="scope.row.postTeachQualOnjob === '0'"
                            type="info"
                        >{{$t('common.text.no')}}</el-tag>
                        <el-tag
                            v-if="scope.row.postTeachQualOnjob === '1'"
                            type="success"
                        >{{$t('common.text.yes')}}</el-tag>
                    </template>
                </edu-table-column>
                <edu-table-column
                    :label="$t('teachers.postTeachQual')"
                    :render-header="labelHead"
                    v-if="this.global.projectId === '2'"
                >
                    <template slot-scope="scope">
                        <el-tag
                            v-if="scope.row.postTeachQual === '0'"
                            type="info"
                        >{{$t('common.text.no')}}</el-tag>
                        <el-tag
                            v-if="scope.row.postTeachQual === '1'"
                            type="success"
                        >{{$t('common.text.yes')}}</el-tag>
                    </template>
                </edu-table-column>
                <edu-table-column
                    :label="$t('teachers.underTeachQual')"
                    :render-header="labelHead"
                    v-if="this.global.projectId === '1'"
                >
                    <template slot-scope="scope">
                        <el-tag
                            v-if="scope.row.underTeachQual === '0'"
                            type="info"
                        >{{$t('common.text.no')}}</el-tag>
                        <el-tag
                            v-if="scope.row.underTeachQual === '1'"
                            type="success"
                        >{{$t('common.text.yes')}}</el-tag>
                    </template>
                </edu-table-column>
                <!--本科生授课资格有效期-->
                <edu-table-column
                    :label="$t('teachers.teachQualValidity')"
                    :render-header="labelHead"
                    v-if="this.global.projectId === '1'"
                >
                    <template slot-scope="scope">{{getTeachQualValidity(scope.row)}}</template>
                </edu-table-column>
                <!--设置授课资格原因-->
                <edu-table-column
                    v-if="this.global.projectId === '2'"
                    :label="$t('teachers.teachQualReason')"
                    prop="teachQualReason"
                    :render-header="labelHead"
                />
                <edu-table-column
                    v-if="this.global.projectId === '4'"
                    :label="$t('teachers.teachQualReason')"
                    prop="teachQualOnjobReason"
                    :render-header="labelHead"
                />
                <edu-table-column :label="$t('teachers.state')" :render-header="labelHead">
                    <template slot-scope="scope">
                        <el-tag
                            v-if="scope.row.stateId !== '1'"
                            type="info"
                        >{{$t('common.text.no')}}</el-tag>
                        <el-tag
                            v-if="scope.row.stateId === '1'"
                            type="success"
                        >{{$t('common.text.yes')}}</el-tag>
                    </template>
                </edu-table-column>
            </el-table>
            <div class="edu-pagination">
                <div class="float-right">
                    <el-pagination
                        :current-page="queryForm.pageNum_"
                        :page-sizes="[20,50,100,500,1000]"
                        :page-size="queryForm.pageSize_"
                        :total="queryForm.total"
                        layout="total, sizes, prev, pager, next, jumper"
                        style="float: right;margin:0;"
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                    />
                </div>
            </div>
        </el-card>

        <el-dialog
            :visible.sync="examineVisible"
            :before-close="handleClose"
            class="teacher-info"
            width="1000px"
            v-drag-dialog
        >
            <div slot="title">
                <span style="font-size: 18px">{{$t('teachers.teacherInfo')}}</span>
                &nbsp;&nbsp;
                <i class="el-icon-warning" style="color: #C0C4CC"></i>
                <span
                    style="font-size: 12px;color: #C0C4CC"
                >&nbsp;&nbsp;{{$t('teachers.changeMessage')}}</span>
            </div>
            <DetailInfoComponent :teacher-info="teacherInfo"></DetailInfoComponent>
        </el-dialog>

        <el-dialog
            :visible.sync="showSetDialog"
            :title="$t('teachers.teachingSetting')"
            :width="$store.state.common.dialogWidth600"
            v-drag-dialog
        >
            <el-form
                :model="postForm"
                label-position="right"
                label-width="140px"
                :rules="rules"
                ref="postForm"
                label-suffix="："
            >
                <el-row>
                    <el-col :offset="2" :span="20">
                        <el-form-item :label="$t('teachers.teachingSetting')" prop="teachQual">
                            <el-select v-model="postForm.teachQual" style="width: 100%" disabled>
                                <el-option
                                    v-for="item in options.departments"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :offset="2" :span="20">
                        <el-form-item
                            :label="$t('arrangement.assistDataCfg.iseffective')"
                            prop="isEffective"
                        >
                            <el-select v-model="postForm.isEffective" style="width: 100%">
                                <el-option
                                    v-for="item in options.isEffective"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <!--本科生授课资格-->
                <el-row v-if="this.global.projectId === '1'">
                    <el-col :offset="2" :span="20">
                        <el-form-item :label="$t('teachers.teachQualValidity')">
                            <div style="display: flex">
                                <el-date-picker
                                    v-model="postForm.underStartTime"
                                    type="date"
                                    align="right"
                                    format="yyyy/MM/dd"
                                    value-format="timestamp"
                                    :picker-options="pickerBeginDateBefore"
                                    :placeholder="$t('permissions.selectStartTime')"
                                ></el-date-picker>
                                <span style="margin: 0 10px;">-</span>
                                <el-date-picker
                                    v-model="postForm.underEndTime"
                                    type="date"
                                    align="right"
                                    format="yyyy/MM/dd"
                                    value-format="timestamp"
                                    :picker-options="pickerBeginDateAfter"
                                    :placeholder="$t('permissions.selectStartTime')"
                                ></el-date-picker>
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if="this.global.projectId === '2'">
                    <el-col :offset="2" :span="20">
                        <el-form-item :label="$t('teachers.teachQualReason')" prop="remark">
                            <el-input
                                v-model="postForm.teachQualReason"
                                type="textarea"
                                :rows="3"
                                maxlength="255"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if="this.global.projectId === '4'">
                    <el-col :offset="2" :span="20">
                        <el-form-item :label="$t('teachers.teachQualReason')" prop="remark">
                            <el-input
                                v-model="postForm.teachQualOnjobReason"
                                type="textarea"
                                :rows="3"
                                maxlength="255"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer">
                <el-button @click="cancel">{{$t('message.cancel')}}</el-button>
                <el-button type="primary" @click="save">{{ $t('message.confirm') }}</el-button>
            </span>
        </el-dialog>
      </template>

      <!-- 教师信息修改（手机号、邮箱） -->
      <TeacherInfoEditComponent v-if="pathKey ==='infoEdit'" :dataInfo="dataInfo" @back="pathKey='main'"/>
    </div>
</template>

<script>
import * as API from 'common/src/api/resource/teachers'
import filters from 'common/src/filters'
import UTILS from 'common/src/utils/utils'
import { queryDic } from 'common/src/api/dictionary'
import DetailInfoComponent from './componet/DetailInfoComponent'
import TeacherInfoEditComponent from "./componet/TeacherInfoEditComponent";
import mixin from 'common/src/mixins/index';

export default {
    name: 'Teachers',
    mixins: [mixin],
    components: {
        TeacherInfoEditComponent,
        DetailInfoComponent
    },
    data() {
        return {
            pathKey: "main",
            dataInfo:{},
            selectTeachers: [], //列表勾选的教师信息
            teacherList: [],
            examineVisible: false,
            teacherInfo: {},
            detailDailog: {
                labelPosition: 'right',
                labelWidth: '120px'
            },
            isExportAll: false,
            examineFileList: [],
            examineInfo: {
                id: '',
                type: 12,
                editExplain: '',
                evidenceList: []
            },
            path: {
              label: this.$t("teachers.teachersMgt"),
              key: "main",
              children: [
                {
                  label: this.$t("teachers.batchEditTeachers"),
                  key: "infoEdit"
                }
              ]
            },
            queryForm: {
                country: '', //* 国籍
                faculty: '', //* 学院
                sex: '', //* 性别
                title: '', //* 职称
                teachQual: '', //* 教师授课资格
                condition: '',
                //showAllTeacher : "1",
                pageNum_: 0,
                pageSize_: 20,
                total: 0,
                minAge: null,
                maxAge: null,
                stateId: null
            },
            postForm: {
                teachQual: '',
                isEffective: '',
                underStartTime: '', //本科是授课资格开始时间
                underEndTime: '',
                teachQualReason: '', //研究生授课资格原因
                teachQualOnjobReason: '' //在职研究生设置授课资格原因
            },
            options: {
                faculty: [],
                teacherType: [],
                stateId: [],
                title: [],
                country: [],
                sex: [],
                departments: [],
                teachQual: [],
                isEffective: [],
                state: [
                    {
                        label: this.$t('message.yes'),
                        value: '1'
                    },
                    {
                        label: this.$t('message.no'),
                        value: '0'
                    }
                ]
            },
            rules: {
                teachQual: [
                    {
                        required: true,
                        message: this.$t('common.pla.pleaseSelect'),
                        trigger: 'blur'
                    }
                ],
                isEffective: [
                    {
                        required: true,
                        message: this.$t('common.pla.pleaseSelect'),
                        trigger: 'blur'
                    }
                ]
            },
            idList: [],
            showSetDialog: false,
            pickerBeginDateBefore: {
                disabledDate: time => {
                    let endTime = this.postForm.underEndTime
                    if (endTime) {
                        return new Date(time).getTime() > new Date(endTime).getTime()
                    }
                }
            },
            pickerBeginDateAfter: {
                disabledDate: time => {
                    let startTime = this.postForm.underStartTime
                    if (startTime) {
                        let endTime = new Date(time).getTime() + 24 * 60 * 60 * 1000 - 1000
                        return endTime <= new Date(startTime).getTime()
                    }
                }
            },
            setId: ''
        }
    },
    watch: {
    pathKey(val) {
      if (val == "main") {
        this.init();
      }
    }
  },
    created() {
        this.initOptions()
        this.init()
    },
    methods: {
        //列表身份证标识转换
        getCard(row) {
            row.cardLable = row.card
            if (row.card && row.card.length > 10) {
                row.cardLable = row.card.slice(row.card.length - 10, row.card.length)
            }
            return row.cardLable
        },

        getTeachQualValidity(row) {
            row.teachQualValidity = null
            if (UTILS.isNotEmpty(row.underStartTime)) {
                row.underStartTime = filters.formatDate(new Date(row.underStartTime), 'yyyy/MM/dd')
                if (UTILS.isNotEmpty(row.underEndTime)) {
                    row.underEndTime = filters.formatDate(new Date(row.underEndTime), 'yyyy/MM/dd')
                    row.teachQualValidity = row.underStartTime + '-' + row.underEndTime
                } else {
                    row.teachQualValidity = row.underStartTime + '- 永久'
                }
            } else {
                if (row.underTeachQual === '0') {
                    row.teachQualValidity = '-'
                } else {
                    row.teachQualValidity = '永久'
                }
            }
            return row.teachQualValidity
        },

        async init() {
            if (
                this.queryForm.minAge &&
                this.queryForm.maxAge &&
                this.queryForm.minAge > this.queryForm.maxAge
            ) {
                this.$message({
                    message: '年龄起始时间不得大于结束时间',
                    type: 'warning'
                })
                return
            }
            let params = _.cloneDeep(this.queryForm)
            if (this.global.isUndergraduate) {
                params.keyword = params.condition
                params.condition = null
            }
            const teachers = await API.findTeacherList(params)
            if (teachers.data && teachers.code === 200) {
                this.teacherList = teachers.data.list
                this.queryForm.total = teachers.data.total_
            }
        },
        batchEditTeachers() {
          this.dataInfo = this.selectTeachers || [];
          if (this.dataInfo.length === 0) {
            this.$message.warning(this.$t('teachers.selectMsg'));
            return;
          }
          this.pathKey = "infoEdit";
        },
        initOptions() {
            this.options.isEffective.push({
                label: this.$t('message.yes'),
                value: '1'
            })
            this.options.isEffective.push({
                label: this.$t('message.no'),
                value: '0'
            })

            const data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['G_GXK', 'X_YX', 'G_JSLB', 'profession', 'G_GJQU', 'G_XBIE']
            }
            queryDic(data).then(res => {
                if (res.code === 200) {
                    // this.fillSelect(res.data);
                    UTILS.fillSelect(
                        {
                            stateId: 'G_GXK',
                            faculty: 'X_YX',
                            teacherType: 'G_JSLB',
                            title: 'profession',
                            country: 'G_GJQU',
                            sex: 'G_XBIE'
                        },
                        res.data,
                        this.options
                    )
                }
            })

            //授课资格设置
            const under = {
                label: this.$t('teachers.underTeachQualLabel'),
                value: '1'
            }
            const post = {
                label: this.$t('teachers.postTeachQualLabel'),
                value: '2'
            }
            const onjob = {
                label: this.$t('teachers.postTeachQualOnjob'),
                value: '3'
            }
            this.options.departments.push(under, post, onjob)

            //是否具备授课资格
            let yes = { label: this.$t('message.yes'), value: '' }
            const no = {
                label: this.$t('message.no'),
                value: '0'
            }
            if (this.global.projectId === '1') {
                yes.value = '1'
                no.value = '-1'
            } else if (this.global.projectId === '2') {
                yes.value = '2'
                no.value = '-2'
            } else {
                yes.value = '3'
                no.value = '-3'
            }
            this.options.teachQual.push(yes, no)
        },
        handleSizeChange(val) {
            this.queryForm.pageSize_ = val
            this.init()
        },
        handleCurrentChange(val) {
            this.queryForm.pageNum_ = val
            this.init()
        },
        handleFilterSubmit() {
            this.init()
        },
        reset() {
            this.queryForm.country = ''
            this.queryForm.faculty = ''
            this.queryForm.sex = ''
            this.queryForm.title = ''
            this.queryForm.teachQual = ''
            this.queryForm.condition = ''
            this.queryForm.minAge = null
            this.queryForm.maxAge = null
            this.queryForm.stateId = null
            this.init()
        },
        handleExportSchemes() {
            let loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(255, 255, 255, .48)'
            })
            let data = _.cloneDeep(this.queryForm)
            data.ids = this.idList
            API.exportTeacher(data).then(res => {
                if (res.code == 200) {
                    this.delayRequest(res.data.key, loading)
                } else {
                    loading.close()
                }
            })
        },
        //异步获取批量结果
        async delayRequest(key, loading) {
            await new Promise(resolve => setTimeout(resolve, 5000))
            API.getReportStatus(key)
                .then(res => {
                    if (res.code == 200 && res.data.status) {
                        loading.close()
                        let path = '/api/baseresservice/teacher/export?path=' + res.data.path
                        window.open(path)
                    } else {
                        this.delayRequest(key, loading)
                    }
                })
                .catch(ex => {
                    this.delayRequest(key, loading)
                })
        },
        // handleExamineScheme(item) {
        //     this.teacherInfo = item;
        //     this.examineInfo.id = item.id;
        //     this.examineVisible = true;
        // },
        handleAvatarPreview() {},
        handleAvatarRemove() {},
        selectionChange(selection) {
            const _this = this
            _this.idList = []
            if (selection.length !== 0) {
                _.forEach(selection, function(item) {
                    _this.idList.push(item.id)
                })

            }
            this.selectTeachers = selection;
        },
        handleUploadSuccess(res, file, fileList) {
            const fileObj = {
                name: file.name,
                objectkey: res.data[file.name].objectkey
            }
            this.examineFileList.push(fileObj)
            this.examineInfo.evidenceList.push(res.data[file.name].objectkey)
        },
        submitExamine() {
            if (this.examineInfo.editExplain === '') {
                this.$message({
                    message: this.$t('teachers.materialRequired'),
                    type: 'warning'
                })
                return
            }

            API.checkTeacherAuth(this.examineInfo).then(res => {
                this.examineVisible = false
                this.examineInfo.editExplain = ''
                this.examineFileList = []
            })
        },
        resetExamine() {
            this.examineInfo.editExplain = ''
            this.examineFileList = []
            this.examineVisible = false
        },
        handleSubmit() {
            if (this.idList.length === 0) {
                this.$noSelectAlert()
                // this.$notify.warning({
                //     title: this.$t("message.prompt"),
                //     message: this.$t("teachers.chooseSomeThing")
                // });
                return
            }
            if (this.idList.length > 1) {
                this.$notify.warning({
                    title: this.$t('message.prompt'),
                    message: this.$t('teachers.onlyChooseOneTea')
                })
                return
            }
            if (this.$refs.postForm) this.$refs.postForm.clearValidate()
            for (let key in this.postForm) {
                this.postForm[key] = ''
            }

            this.setId = this.idList[0]
            let teacher = this.selectTeachers[0]
            //组装数据
            if (this.global.projectId === '1') {
                //本科生
                this.postForm.teachQual = '1'
                this.postForm.isEffective = teacher.underTeachQual
                if (UTILS.isNotEmpty(teacher.underStartTime)) {
                    this.postForm.underStartTime = new Date(teacher.underStartTime).getTime()
                }

                if (UTILS.isNotEmpty(teacher.underStartTime)) {
                    this.postForm.underEndTime = new Date(teacher.underEndTime).getTime()
                }
            } else if (this.global.projectId === '2') {
                this.postForm.teachQual = '2'
                this.postForm.isEffective = teacher.postTeachQual
                this.postForm.teachQualReason = teacher.teachQualReason
            } else {
                this.postForm.teachQual = '3'
                this.postForm.isEffective = teacher.postTeachQualOnjob
                this.postForm.teachQualOnjobReason = teacher.teachQualOnjobReason
            }

            //this.postForm.teachQual = "";
            //this.postForm.isEffective = "";
            this.showSetDialog = true
        },
        handleCondition() {
            this.init()
        },
        handleNameClick(row) {
            this.teacherInfo = row
            this.examineVisible = true
        },
        cancel() {
            this.showSetDialog = false
        },
        save() {
            this.$refs.postForm.validate(valid => {
                if (!valid) {
                    return
                }

                let data = { id: this.setId }
                if (this.postForm.teachQual == 1) {
                    data.underTeachQual = this.postForm.isEffective
                    if (
                        UTILS.isNotEmpty(this.postForm.underEndTime) &&
                        UTILS.isEmpty(this.postForm.underStartTime)
                    ) {
                        //结束时间填了，开始时间必填
                        this.$message({ type: 'error', message: '请填写授课资格有效期的开始日期' })
                        return
                    }
                    data.underStartTime = this.postForm.underStartTime
                    data.underEndTime = this.postForm.underEndTime
                } else if (this.postForm.teachQual == 2) {
                    data.postTeachQual = this.postForm.isEffective
                    data.teachQualReason = this.postForm.teachQualReason
                } else {
                    data.postTeachQualOnjob = this.postForm.isEffective
                    data.teachQualOnjobReason = this.postForm.teachQualOnjobReason
                }
                API.setQualification(data).then(res => {
                    if (res.code == 200) {
                        this.showSetDialog = false
                        this.$message({
                            type: 'success',
                            message: this.$t('message.saveSuccess')
                        })
                        this.handleFilterSubmit()
                    }
                })
            })
        },
        labelHead(h, { column, $index }) {
            return h('span', { attrs: { title: column.label } }, [column.label])
        }
    }
}
</script>

<style lang="scss">
.box-card {
    margin-bottom: 4px;
}
/* .elec-stu-table {
	text-align: left;
	margin: 3px auto;
    width: 90%;
    height: 500px;
	border-color: #c0c4cc;
	border-style: solid;
	border-width: 0 1px 1px 0;
	td {
		padding: 6px;
		border-color: #c0c4cc;
		border-style: solid;
		border-width: 1px 0 0 1px;
	}
	.td-name {
		width: 16%;
        text-align: right;
        background:#F2F6FC;
	}
} */
</style>

